<template>
  <div>

  </div>
</template>
<script>
import { defineComponent, getCurrentInstance, onBeforeUnmount, onMounted } from 'vue';
export default defineComponent({
  name: 'Input',
  props: {
    rules: {
      default: () => [],
      type: Array
    },
    modelValue: {
      default: null,
      type: String
    }
  },
  setup(props) {
    const form = inject("form");
    const uid = getCurrentInstance().uid;
    onMounted(() => {
      form.bind({ validate, uid });
    });
    onBeforeUnmount(() => {
      form.unbind(uid);
    });
    function validate() {
      //验证逻辑略
      let result = true;
      props.rules.forEach(rule => {
        const value = rule(props.modelValue);
        if (!value) result = value;
      })
      return result
    }
  }
})


</script>
<style lang="">

</style>